package lu.med.praxiswahl.wahlumed.client.oprechnungen;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

import lu.med.praxiswahl.wahlumed.client.utilities.UniCode;


/**
 * 
 * @author Lars Holger Roth
 */
public class OPRechnungenTableKlasseZwei extends JTable implements
	ActionListener
{
    private OPRechnungenTableModelKlasseZwei model;

    public OPRechnungenTableKlasseZwei(OPRechnungenTableModelKlasseZwei model)
    {
	this.setModel(model);
	this.model = model;
	this.setDefaultRenderer(Object.class,
		new OPRechnungenCellRendererKlasseZwei(model));
	// this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	this.selectionModel
		.addListSelectionListener(new OPRechnungenTableSelectionListenerKlasseZwei(
			model));

	this.addMouseListener(new MouseAdapter()
	{
	    @Override
	    public void mouseReleased(MouseEvent evt)
	    {
		if (evt.isPopupTrigger())
		{
		    showMenu(evt);
		}
	    }
	});

	TableColumn column = null;
	for (int i = 0; i < 7; i++)
	{
	    column = this.getColumnModel().getColumn(i);
	    switch (i)
	    {
	    case 0:
		column.setPreferredWidth(30);
		break;
	    case 1:
		column.setPreferredWidth(40);
		break;
	    case 2:
		column.setPreferredWidth(150);
		break;
	    case 3:
		column.setPreferredWidth(160);
		break;
	    case 4:
		column.setPreferredWidth(40);
		break;
	    case 5:
		column.setPreferredWidth(80);
		break;
	    case 6:
		column.setPreferredWidth(80);
		break;
	    }
	}
    }

    @Override
    public void actionPerformed(ActionEvent arg0)
    {
	model.deleteRow();

    }

    public void showMenu(MouseEvent evt)
    {
	JPopupMenu menu = new JPopupMenu();
	JMenuItem item = new JMenuItem("Eintrag l" + UniCode.getoe() + "schen");
	item.addActionListener(this);
	menu.add(item);
	menu.show(this, evt.getX(), evt.getY());
    }

}
